package com.jblapp.icu.sms;

import com.jblapp.icu.ui.RegisterConfirmActivity;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

public class ReadSmsThread implements Runnable {
	private Context context = null;
	private Handler msgHandler = null;
	private String phoneNumber = null;
	private String textMsg = null;
	private SmsUtils smsUtils = null;
	private Message msg = null;
	private final static String TAG = "ReadSmsThread";

	public ReadSmsThread(Context context, Handler msgHandler, String phoneNumber) {
		this.context = context;
		this.msgHandler = msgHandler;
		this.phoneNumber = phoneNumber;
	}

	@Override
	public void run() {
		smsUtils = new SmsUtils(context);
		textMsg = smsUtils.readSmsMsg(phoneNumber);
		msg = new Message();
		if (null == textMsg || "".equals(textMsg)) {
			msg.what = RegisterConfirmActivity.ERROR;
			msg.obj = null;
		} else {
			msg.what = RegisterConfirmActivity.READED_SMS;
			msg.obj = textMsg;
			Log.e(TAG, textMsg);
		}
		msgHandler.sendMessage(msg);
	}
}
